﻿using CTP.CRM.Repository;
using CTP.CRM.Repository.Demo.Entitys;

namespace CTP.CRM.Repository.Demo.Services
{
    public class CanalRepository : BiCenterRepository<DemoEntity>, ICanalRepository, IScopedDependency
    {
        #region 根据主键获取单条数据

        /// <summary>
        /// 根据主键获取单条数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task<DemoEntity> GetById1(int id)
        {
            /*

            //以下两种方法都不会因为没找到数据而抛异常
            var model1 = base.GetFirst(m => m.Id == 0);
            var model = base.GetSingle(m => m.Id == 0);

            //同样的写法在linq下，如果不加 OrDefault 一定会报错
            var model = base.GetList().Single(m => m.Id == 0);
            var model1 = base.GetList().First(m => m.Id == 0);

            */
            return base.GetSingleAsync(it => it.Id == id);
        }

        #endregion 根据主键获取单条数据
    }
}